package com.atsmart.app.sql;

import com.atsmart.app.model.ClientDisInfo;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteStatement;

public class ClientDisSqlHelper {

	private SQLiteDatabase db = null;

	/**
	 * 打开数据库
	 */
	public void open(SqlHelper dh) {
		// dh = new SqlHelper(null, "atsmart", null,SqlHelper.getDBVersion());
		db = dh.getWritableDatabase();
	}

	public synchronized void addClientDisInfo(ClientDisInfo at) {
		if (at == null) {
			return;
		}
		String strSql = "insert or replace into client_dis_info (pol_id,distance,lon,lat) values(?,?,?,?);";
		try {
			SQLiteStatement stm = db.compileStatement(strSql);
			stm.bindLong(1, at.getId());
			stm.bindDouble(2, at.getDistance());
			stm.bindDouble(3, at.getLon());
			stm.bindDouble(4, at.getLat());
			stm.execute();
			stm.clearBindings();
			stm.close();
		} catch (Exception e) {
			// will not happen
		}
	}

	public void deleteAttribute() {
		// db.delete("position_attribute", null, null);
		db.execSQL("delete from client_dis_info");
	}

}
